﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Ventas.Api.Models;
using Ventas.Data.Entities;
using Ventas.Data.Managers;

namespace Ventas.Api.Controllers
{
    public class CategoryController : ApiController
    {
        //Get
        public IEnumerable<CategoryModel> Get()
        {
            return CategoryManager.GetList("").Select(t => new CategoryModel
            {
                Id = t.Id,
                Name = t.Name,
                Description = t.Description,
            });
        }
        //
        public CategoryModel Get(Guid id)
        {
            Category t = CategoryManager.GetById(id);
            return new CategoryModel
            {
                Id = t.Id,
                Name = t.Name,
                Description = t.Description,
            };
        }
        //
        public CategoryModel Post(CategoryModel m)
        {
            Category t = CategoryManager.Create(new Category
            {
                Name = m.Name,
                Description = m.Description,
            });
            return new CategoryModel
            {
                Id = t.Id,
                Name = t.Name,
                Description = t.Description,
            };
        }
        //
        public CategoryModel Put(Guid id, [FromBody] CategoryModel m)
        {
            Category t = CategoryManager.Update(new Category
            {
                Id = id,
                Name = m.Name,
                Description = m.Description,
            });
            return new CategoryModel
            {
                Id = t.Id,
                Name = t.Name,
                Description = t.Description,
            };   
        }
        //
        public void DeleteXxxx(Guid id)
        {
            CategoryManager.Delete(id);
        }
    }
}